package com.task.manage.system.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.task.manage.common.annotation.Log;
import com.task.manage.common.enums.BusinessType;
import com.task.manage.system.domain.TaskReveiveRecord;
import com.task.manage.system.service.ITaskReveiveRecordService;
import com.task.manage.common.core.controller.BaseController;
import com.task.manage.common.core.domain.AjaxResult;
import com.task.manage.common.utils.poi.ExcelUtil;
import com.task.manage.common.core.page.TableDataInfo;

/**
 * 任务领取记录Controller
 *
 * @author ruoyi
 * @date 2024-05-11
 */
@Controller
@RequestMapping("/system/record")
public class TaskReveiveRecordController extends BaseController {
    private String prefix = "system/record";

    @Autowired
    private ITaskReveiveRecordService taskReveiveRecordService;

    @RequiresPermissions("system:record:view")
    @GetMapping()
    public String record() {
        return prefix + "/record";
    }

    /**
     * 查询任务领取记录列表
     */
    @RequiresPermissions("system:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskReveiveRecord taskReveiveRecord) {
        startPage();
        List<TaskReveiveRecord> list = taskReveiveRecordService.selectTaskReveiveRecordList(taskReveiveRecord);
        return getDataTable(list);
    }

    /**
     * 导出任务领取记录列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "任务领取记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskReveiveRecord taskReveiveRecord) {
        List<TaskReveiveRecord> list = taskReveiveRecordService.selectTaskReveiveRecordList(taskReveiveRecord);
        ExcelUtil<TaskReveiveRecord> util = new ExcelUtil<TaskReveiveRecord>(TaskReveiveRecord.class);
        return util.exportExcel(list, "任务领取记录数据");
    }

    /**
     * 新增任务领取记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

/*    *//**
     * 新增保存任务领取记录
     *//*
    @RequiresPermissions("system:record:add")
    @Log(title = "任务领取记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskReveiveRecord taskReveiveRecord) {
        return toAjax(taskReveiveRecordService.insertTaskReveiveRecord(taskReveiveRecord));
    }*/

    /**
     * 修改任务领取记录
     */
    @RequiresPermissions("system:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TaskReveiveRecord taskReveiveRecord = taskReveiveRecordService.selectTaskReveiveRecordById(id);
        mmap.put("taskReveiveRecord", taskReveiveRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务领取记录
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "任务领取记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskReveiveRecord taskReveiveRecord) {
        return toAjax(taskReveiveRecordService.updateTaskReveiveRecord(taskReveiveRecord));
    }

    /**
     * 删除任务领取记录
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "任务领取记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(taskReveiveRecordService.deleteTaskReveiveRecordByIds(ids));
    }
}
